#include <stdio.h>
#include <string.h>

int myAtoi(char *s)
{
    if (s == NULL)
    {
        return 0;
    }
    while(*s == ' ')
    {
        s++;
    }

    if ((*s > '9' || *s < '0' ) && (*s != '+' && *s != '-'))
    {
        return 0;
    }

    int flag = s[0] == '-' ? -1 : 1;
    int num = 0;
    int conut = 0;
    char *ptr = s;
    if (s[0] == '-' || s[0] == '+' )
    {
        if (s[1] <= '9' && s[1] >= '0')
        {
            while (*ptr == '0')
            {
                ptr++;
                num++;
            }
            for (int i = num+1; i < strlen(s); i++)
            {
                if (s[i] <= '9' && s[i] >= '0')
                    conut = (s[i] - '0') + conut *10;
                else
                    return conut*flag;
            }
        }
        else
        {
             return 0;
        }
           
    }

    if((s[0] <= '9' && s[0] >= '0'))
    {
        while (*ptr == '0')
        {
            ptr++;
            num++;
        }
        for (int i = num; i < strlen(s); i++)
        {   
            printf("%c\n",s[i]);
            if (s[i] <= '9' && s[i] >= '0')
                conut = (s[i] - '0') + conut *10;
            else
                return conut*flag;
        }
    }
    return conut * flag;
}

int main()
{
    char s[] = "  +250_50";
    printf("atoi = %d\n", myAtoi(s));

    return 0;
}